package high.concurrent.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 创建短链码分片的表位后缀
 */
public class CreateCodeSuffixTableConfig {

    /**
     * 存储表后缀集合
     */
    private static List<String> shortLinkTableSuffixList = new ArrayList<>();

    private static Random random = new Random();
    /**
     * 向集合中添加现有的表后缀，有2个表分别是0，a，所以集合就暂时存0,a
     */
    static {
        shortLinkTableSuffixList.add("0");
        shortLinkTableSuffixList.add("1");
        shortLinkTableSuffixList.add("2");
        shortLinkTableSuffixList.add("3");
        shortLinkTableSuffixList.add("4");
        shortLinkTableSuffixList.add("5");
        shortLinkTableSuffixList.add("6");
        shortLinkTableSuffixList.add("7");
        shortLinkTableSuffixList.add("8");
        shortLinkTableSuffixList.add("9");
        shortLinkTableSuffixList.add("a");
        shortLinkTableSuffixList.add("b");
        shortLinkTableSuffixList.add("c");
        shortLinkTableSuffixList.add("d");
        shortLinkTableSuffixList.add("e");
        shortLinkTableSuffixList.add("f");
        shortLinkTableSuffixList.add("g");
        shortLinkTableSuffixList.add("h");
        shortLinkTableSuffixList.add("i");
    }

    public static String getShortLinkTableSuffix(){
        int suffix = random.nextInt(shortLinkTableSuffixList.size());
        return shortLinkTableSuffixList.get(suffix);
    }

}
